package com.android.presenter.info;

import com.android.model.entity.res.OrderResult;
import com.android.model.info.UserModel;
import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.presenter.iview.ICancelOrderResultView;
import com.android.util.log.LogUtil;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 撤单
 */

public class CancelOrderPresenter extends BasePresenter<ICancelOrderResultView> {

    private static final String TAG = CancelOrderPresenter.class.getSimpleName();
    private UserModel mUserModel;

    public CancelOrderPresenter(ICancelOrderResultView iCancelOrderResultView) {
        super(iCancelOrderResultView);
        mUserModel = UserModel.getInstance();
    }

    public void cancelOrder(String accountId,
                            String orderId,
                            String session) {

        mUserModel.cancelOrder(accountId, orderId,session, new HttpObserver<OrderResult>() {
            @Override
            public void onSuccess(OrderResult orderResult) {
                LogUtil.e(TAG, "成功！");
                if (mIView != null) {
                    mIView.orderCancelSuccess(orderResult);
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "失败码：" + errType + "》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.orderCancelFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
